package com.android.xunxian.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.xunxian.utils.Util;
import com.oa.android.R;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 备注信息
 * Created by  on 2016/7/20.
 */
public class RemarksActivity extends Activity implements View.OnClickListener{


    @InjectView(R.id.close)
    ImageView close;
    @InjectView(R.id.title_text)
    TextView titleText;
    @InjectView(R.id.ritgh_icon)
    ImageView ritghIcon;
    @InjectView(R.id.ritgh_text)
    TextView ritghText;
    @InjectView(R.id.input)
    EditText input;
    private String imgPath;
    private String id;
    private String fileName;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.remarks_activity);
        ButterKnife.inject(this);
        titleText.setText("添加备注");
        close.setOnClickListener(this);
        ritghText.setOnClickListener(this);
        id=getIntent().getStringExtra("id");
        ritghText.setText("保存");
        ritghText.setVisibility(View.VISIBLE);
        imgPath = Environment.getExternalStorageDirectory().getPath()
                + File.separator + "Xunxian" + File.separator +id + File.separator;
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close:
                finish();
                break;
            case R.id.ritgh_text:
                if (input.getText().toString().length()>0){
                    Date nowTime = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                            "yyyyMMddHHmmss");
                   String time = simpleDateFormat.format(nowTime);
                    fileName=id+"_"+time+".txt";
                    new Util(this).writeTxtToFile(input.getText().toString(),imgPath,fileName);
                    Intent intent=new Intent();
                    intent.putExtra("name",fileName);
                    intent.putExtra("time",time);
                    setResult(RESULT_OK,intent);
                    finish();

                }   else {
                    Toast.makeText(getApplicationContext(),"请输入备注信息",100).show();
                }

                break;

        }
    }
}
